package com.pineapple.module.web.calarea;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.pineapple.module.core.calarea.domain.CalAreaModel;

public class CalAreaAction  extends ActionSupport implements ModelDriven<CalAreaModel> {
	private static final long serialVersionUID = -3661000161146714152L;


    private CalAreaModel model = new CalAreaModel();

	public String init(){
		HttpSession session = ServletActionContext.getRequest().getSession();
        if(session.getAttribute("user")==null){
        	return "init";
        }


    	int area = (int)((model.getWidthArea() * model.getHeightArea()) / 0.32) ;
    	List<String> lstSearch = new ArrayList<String>();
        for (int i = 0; i < area; i++) {
        	lstSearch.add(i+"");
		}
        model.setTotal(area);
		session.setAttribute("area", area);

        model.setLstSearch(lstSearch);
		return "search";
	}


	@Override
	public CalAreaModel getModel() {
		return model;
	}
}
